package system.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import core.shiro.ShiroUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/3/15.
 */
public class VoucherHeadDao {

    public boolean insert(Record record){
        return Db.save("voucher_head", record);
    }


    public Record getById(int id) {
        return Db.findFirst("select * from voucher_head where voucher_id = ?", id);
    }


    public List getIdsByPeriod(String period){
        int userid = ShiroUtils.getUserId();
        //根据用户id和period查询出所有的记账凭证id
        StringBuilder regex = new StringBuilder().append(userid).append(period).append("______");
        List ids = Db.query("select voucher_id from voucher_head where voucher_id like ?", regex.toString());
        return ids;
    }


    public boolean deleteById(int voucher_id) {
        return Db.deleteById("voucher_head", "voucher_id", voucher_id);
    }
}
